-module (web_code).
-include_lib ("nitrogen/include/wf.inc").
-compile(export_all).

main() -> 
	#template { file="./wwwroot/template.html"}.

title() ->
	"Hertz :: Coder".

handle_menu() ->
    menu:exec(fun(_) ->
		      wf:render([#label{text = ":D"}])
		      end, []).

body() ->
    NotConnectedSubset = get_functions(false),
    ConnectedSubset = get_functions(true),

    %Choose what to display
	Body = case  wf:session(connected) of
	    true ->
		ConnectedSubset;
	    false ->
		NotConnectedSubset
	end,
    handle_menu(),
    wf:render(Body).
	
event(_) -> ok.

get_functions(Save) ->
    A = case Save of
	    true ->
		Content = [ #button{text="Sauvegarder", actions=helper:act(?MODULE, save_to_rev) },
		  #button{text="Nouvelle révision", actions=helper:act(?MODULE, save_new_rev) },
		  #button{text="Supprimer cette révision", actions=helper:act(?MODULE, delete_rev) }
		 ],
		[#rounded_panel { color=gray, body=Content }];
	    _ ->
		[]
	end,
    B = [#rounded_panel { color=gray, body= [
					     #button{text="-", actions=helper:act(?MODULE, shorten_codebox) },
					     #button{text="+", actions=helper:act(?MODULE, lengthen_codebox) }
					    ]}],
    A ++ B.

